<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>待发布商品</title>
</head>

<style>
#flex div{
	height:45px;
	line-height:36px;
}
</style>

<body>
<div class="container">

    <div class="comm_content">
            <div class="search-box">
                <div style="position:relative">
                    <form id="search_form" onsubmit="return false;" class="form-inline">
                        <table>
                            <tbody>
                                <tr>
                                    <td>
	                                    <span>
	                                        商品类目 ：
	                                        <select name="bigCategoryID" id="bigCategoryID" class="form-control">
	                                            <option value="0">请选择</option>
	                                            <!--{foreach from=$category item=g}-->
													<option value="<!--{$g.bigCategoryID}-->"><!--{$g.name}--></option>
												<!--{/foreach}-->
	                                        </select>
	                                    </span>

	                                    <span>
				                        	商品款号：
				                        	<input type="text" class="form-control w150" id="product_code" name="product_code">
				                        </span>
				                        <span>
				                        	商品名称：
				                        	<input type="text" class="form-control w150" id="goodsName" name="goodsName">
				                        </span>
				                        
				                        <span>
	                                        上下架状态 ：
	                                        <select name="useFlg" id="useFlg" class="form-control">
	                                            <option value="">请选择</option>
	                                            <option value="1">上架</option>
	                                            <option value="0">下架</option>
	                                        </select>
	                                    </span>
	                                    
                                        <span><input type="button" value="查询" class="btn btn-primary" onclick="goods.search();" /></span>
                                        <span><input type="button" value="重置" class="btn btn-warning" onclick="goods.clear();" /></span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>

<script type="text/javascript">
    $("#flex").flexigrid({
        url:"/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=1&xjx=none",
        dataType: "json",
        colModel : [
	        {display: "操作", width : 200, align: "center"},
	        {display: "款号", width : 200},
	        {display: "商品名称",width : 300},
	        {display: "类目", width : 200},
        ],
        <!--{if $edit_permission}-->
        buttons : [
        	//{name: "全选/全不选", onpress : "goods.selectAll"},
            //{name: "批量预上架", onpress : "goods.upForsale"},
            //{name: "批量预下架", onpress : "goods.downForsale"},
            //{name: "批量同步", onpress : "goods.toSale"}
        ],
        <!--{/if}-->
        sortname: "createTIme",
        sortorder: "desc",
        usepager: true,
        rp: 20,
        useRp: true,
        showTableToggleBtn: true
    });
    
    var goods = {
    	
        postID_str  : '' ,

		allFlg		: 0 ,
		
        //商品列表
        search: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({newp: 1,params: dt}).flexReload();
        },

        load: function() {
            $("#flex").flexReload();
        },
        
        toSale: function() {
			this.postID_str = '';
            $.each($('#flex').find('tr'), function(k, v) {
                if ($(v).hasClass('trSelected')) {
                    goods.postID_str += '_' + $(v).attr('id').replace('row', '');
                }
            });

            if (this.postID_str == ''){
                E.alert("请选择要同步的商品");
                return false ;
            }
            
           	E.confirm('您确定要同步选中的商品吗？', 'goods.doConfirm');
        },
        
        doConfirm: function(){
        	E.ajax_post({
        		url: "/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=6",
        		data: {
        			postID_str: goods.postID_str,
        		},
        		call: 'goods.saleCall'
        	});
        },
        
        saleCall: function(o){
        	if (o.code == 200) {
        		E.alert(o.message, 2, 'E.refresh');
        	} else {
        		E.alert(o.message);
        	}
        },
        
        //全选
        selectAll : function () {
        	if(goods.allFlg == 0){
        		$("[id ^='row']").addClass("trSelected");
        		goods.allFlg = 1 ;
        	}else{
        		$("[id ^='row']").removeClass("trSelected");
        		goods.allFlg = 0 ;
        	}
        },
        
        //重置
        clear: function(){
        	$("#product_code").val('');
	        $("#goodsName").val('');
	        $("#cityID").val('0');
	        $("#bigCategoryID").val('0');
	        $("#useFlg").val('');
            goods.search();
        },
        
        focusSort: function(postID){
        	this.cPostid = postID;
        	this.cSort = E.trim($('#sort_' + postID).val())
        },
        
        //修改分类排序
        editSort: function(postID, cityID){
        	if (!E.isInt(postID) || !E.isInt(cityID)) {
        		E.alert('参数错误，请刷新页面后重新操作');
        		return false;
        	}
        	
        	var sortOrder = E.trim($('#sort_' + postID).val());
        	if (!E.isInt(sortOrder)) {
        		E.alert('参数错误，请刷新页面后重新操作');
        		return false;
        	}

        	E.ajax_post({
        		url: "/invokingAjax-backend/goods/goodsEdit.ajax?operFlg=4",
        		data: {
        			postID: postID,
        			sortOrder: sortOrder,
        			cityID: cityID
        		},
        		call: 'goods.sortCall'
        	});
        },
        
        sortCall: function(o){
        	if (o.code != 200) {
        		E.alert(o.message);
        		$('#sort_' + this.cPostid).val(this.cSort)
        	}
        },

        //基本信息编辑
        listEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsEdit.pscript?operFlg=2&postID='+postID;
        },
        
        //sku信息编辑
        skuEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsEdit.pscript?operFlg=3&postID='+postID;
        },
        
        //生产信息编辑
        productEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsEdit.pscript?operFlg=4&postID='+postID;
        },
        
         //商品图片编辑
        picEdit: function(postID){
            self.location = '/quanliadmin/app/goods/goodsEdit.pscript?operFlg=5&postID='+postID;
        }
        
    }; 
</script>
</body>
</html>